from django.contrib.auth.models import Permission, Group
from django.contrib.contenttypes.models import ContentType
from rest_framework.generics import ListAPIView
from rest_framework.permissions import IsAdminUser
from rest_framework.viewsets import ModelViewSet
from users.models import User
from meiduo_admin.serializers.quanxian import PermissionPermsSerializer, PermissionContenttypesSerializer, \
    PermissionGroupsSerializer, PermissionSimpleSerializer, PermissionAdminsSerializer, PermissionGroupsSimpleSerializer


class PermissionPermsView(ModelViewSet):
    permission_classes = [IsAdminUser]
    serializer_class = PermissionPermsSerializer
    queryset = Permission.objects.all()


class PermissionContenttypesView(ListAPIView):
    permission_classes = [IsAdminUser]
    serializer_class = PermissionContenttypesSerializer
    queryset = ContentType.objects.all()
    pagination_class = None


class PermissionGroupsView(ModelViewSet):
    permission_classes = [IsAdminUser]
    serializer_class = PermissionGroupsSerializer
    queryset = Group.objects.all()


class PermissionSimpleView(ListAPIView):
    permission_classes = [IsAdminUser]
    serializer_class = PermissionSimpleSerializer
    queryset = Permission.objects.all()
    pagination_class = None


class PermissionAdminsView(ModelViewSet):
    permission_classes = [IsAdminUser]
    serializer_class = PermissionAdminsSerializer
    queryset = User.objects.filter(is_staff=True)


class PermissionGroupsSimpleView(ListAPIView):
    permission_classes = [IsAdminUser]
    serializer_class = PermissionGroupsSimpleSerializer
    queryset = Group.objects.all()
    pagination_class = None
